<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="author" content="zhuwoquan">
	<title>采购单任务管理</title>
	<script language="javascript" src="../script/common.js" type="text/javascript"></script>
	<script language="javascript" type="text/javascript">
	//全局变量
	var qt = {};				//数据表格对象
	var orderId="";				//采购单ID
	var type="";					//钻石类型
	var cOrg;				//取当前地址
	var detail_editable;
	var selectedOrg;
	//页面控件初始化
	function load(){
		Eui.showNavigation();//导航
		setPages(["listview","detread","listview1"])
		cOrg = Common.cOrg()
		//初始化申请单状态("新建","申请","通过","拒绝","确认")

		var statusList
		if(cOrg.orgLevel == Constants.ORG_LEVEL_HQ){
			 statusList = Common.getSubsetItems("PurchaseBillStatus", [Constants.PurchaseBillStatus_NEW, Constants.PurchaseBillStatus_FINISH]);
		}else{
			 statusList = Common.getSubsetItems("PurchaseBillStatus", [Constants.PurchaseBillStatus_NEW, Constants.PurchaseBillStatus_ACCPECTED]);
		}
//      searchForm.currentOrg.value = cOrg.id;
        setOrg(cOrg);	 	
		Common.initDict(searchForm.type,"PurchaseBillType","全 部");	
		Common.initDict(searchForm.diamondType,"diamondType","全 部");
		Eui.initBeginDateInput("beginDateTd","创建日期开始","searchForm","startrequestDate","endrequestDate","date");
		Eui.initEndDateInput("endDateTd","创建日期结束","searchForm","startrequestDate","endrequestDate","date");
		createTable();
	}
	
	//生成查询语句
	function createTable(){
		var columns = [];
		columns[0] = {type:"checkbox"};
		columns[1] = {render:numFunc};
		columns[3] = {defOrder:true}
		var discolumns;
		columns[14] = {title:"操作",width:12,render:operationFunc,align:"center",order:false};
		discolumns = [0,1,2,3,4,5,6,7,8,9,10,14]
		qt = new QueryTable("manage_pbill_submit","searchForm","datalist",columns,{
			displayColumns:discolumns,
			title:"采购单入库列表",
			paramFunc: function(){
				return {
					purchaseBillStatus:Constants.PurchaseBillStatus_ACCPECTED
				};
			}
		});
	}
	//数据处理方法
	function numFunc(v){
		return "<a href=# onclick=showDetail('"+v+"')>"+v+"</a>"
	}
	
	//处理数据 点id进入编辑页面
	function operationFunc(v,r){
		var html="<div style='color:gray'>";
		html += "<a href=# onclick=storeIn('"+r[0]+"',"+r[4]+")>入库</a> "
//		if(cOrg.orgLevel == Constants.ORG_LEVEL_HQ)
//			html += "<a href=# onclick=\"unConfirmBill("+r[0]+");return false;\">撤销</a>"
		return html;
	}
	//显示静态明细
	function showDetail(id){
		if (id != null){
			orderId=id
			requestframe.document.location.href = "../aita/purchase_bill_detail.html?id="+id;
			switchPage("listview1")
		}
	}

	//撤销
	function quash(){
		var id1=$('makecardform').id.value;
		DWR.call("cardRequestService.cancelCardReqOrder",id1,function(showapply){
			 showInformation("撤销成功!");
			 switchPage("listview");
			 qt.showTable();
		},{disCtrl:$('bcz')});
	}
	//提交
	function quash3(){
		var id1=$('makecardform').id.value;
		DWR.call("cardRequestService.commitCardReqOrder",id1,function(showapply){
			 showInformation("提交成功!");
			 switchPage("listview");
			 qt.showTable();
 		},{disCtrl:$('bcz')});
	}
	function formatOrderObj(apply){
		var order = apply.order
	 	var status= order.status;
	 	order.status = Common.getText("cardbill_status",status);
		order.diamondType = apply.diamondType.name;
		order.createTime= Format.formatToMM(order.createTime);
		if(order.verifyTime){
			order.verifyTime = Format.formatToMM(order.verifyTime);
		}
		$("makecardform").id.value = order.id
		return order;
	}
	//撤销
	function unConfirmBill(id){
		DWR.call("cardRequestService.getRequestOrder",id,function(apply){
			var status = apply.order.status;
		    var order = formatOrderObj(apply)
			Common.showDetail("detread",order);
			$("query").innerHTML = "<button type='button'  id='bcz' name='bcz'  onclick='quash()' >撤   销</button> ";
	
			switchPage('detread');
		});
	}
	//入库操作
	function storeIn(id,amount){
		if(amount == 0){
			showInformation("采购单的采购数量为0,不能进行采购!");
			return;
		}	
		DWR.call("purchaseBillService.goNextStep",id,Constants.PurchaseBillStatus_FINISH,function(apply){
			if (apply) {
				showInformation("入库操作成功!");
				qt.showTable();
			}
			else {
				showInformation("入库操作失败，请重试!");
				return ;
			}
//			var status = apply.order.status;
//		 	var bill = formatOrderObj(apply)
//			Common.showDetail("detread",bill);
//			switchPage('detread');
		});
	}
	//页面刷新返回
	function backShow(){
		$("orderIdTd").style.display="none"
		switchPage('listview')
		qt.showTable();
	}
	//无页面刷新返回
	function backShow1(){
		switchPage('listview')
	}
	//校验时间和显示类表数据
   function selectDate(){
		searchForm.organization.value = cOrg.id;
		qt.showTable();
   }
	
	//选择机构方法
		function selectOrganization(b){
			var opts = {funcType : Constants.SELORG_ALL} //获得直属子节点
		
			if (b){
				SystemMgnt.selOrg(setSearchOrg,opts);
			}else{
				SystemMgnt.selOrg(setOrg,opts);
			}
		}
		
        //searchform 选择机构 回调方法 
		function setSearchOrg(sorg){	
			searchForm.orgName.value = sorg.name;
			searchForm.organization.value = sorg.id;
		}
		
        //选择机构 回调方法
        function setOrg(sorg) {
        	selectedOrg = sorg;
            searchForm.reset();
            searchForm.organization.value = sorg.id;
            searchForm.orgName.value = sorg.name;
        }
	//选择操作员
        function selOper() {
			SystemMgnt.selOperator(function(v) {
				if (!v) return;
				searchForm.operatorName.value = v.name;
//				searchForm.member.value = v.id;
			}, {orgId:selectedOrg.id})
		}
		
	</script>
</head>

<body onload="load()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<!--查询静态页面部分-->
		<div id="listview" >	
			<!--查询条件form-->
			<div class="searchForm">
				<form id="searchForm" name="searchForm">
					<input type="hidden" name="organization" >
					<table cellSpacing=0 cellPadding=6 width="100%" border=0 class="col4 label6">
						<tr>
							<td><label>单据编号</label> <input type="text" name="requestid" onblur="checkV(this,'number')" maxlength=12 ></td>
							<td id="beginDateTd"></td>
							<td id="endDateTd"></td>
							<td><label>采购类型</label> <select name="type"><option></option></select></td>
						</tr>
						<tr>
						<td><label>钻石类型</label> <select name="diamondType"><option></option></select></td>
							
							<td><label>所属机构</label> <input type="text" name="orgName" readonly class="readonly"  onclick="selectOrganization();">
							<a class=orga href=# onclick="selectOrganization();">&nbsp;&nbsp;</a></td>
                			<td><label>操&nbsp;作&nbsp;员</label> <input type="text" name="operatorName" readonly class="readonly">
							<a class=orga href=# onclick="selOper();">&nbsp;&nbsp;</a></td>
							
							<td><button type="button" onclick="selectDate()" >查   询</button></td>
						</tr>
					</table>
				</form>
			</div>
				<!--查询结构列表-->
				<div id="datalist"></div>
		</div>
	<!--明细静态显示部分-->
	<div class="detread" id="detread" style='display:none;'>
		<form id="makecardform" name="makecardform">
		<input type="hidden" name="id">
			<div class=form>
			<div class="formTitle">单据明细</div>
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="viewTable">
					<tr>
						<td>
							<label>单据编号</label> <span id="id"></span>
						</td>
						<td>
							<label>钻石类型</label> <span id="diamondType"></span>
						</td>
					</tr>
					<tr>
						<td>
							<label>需求数量</label> <span id="amount"></span>
						</td>
						<td>
							<label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label> <span id="status"></span>
						</td>
					</tr>
					<tr>
						<td>
							<label>创建时间</label> <span id="createTime"></span>
						</td>
						<td>
							<label>完成日期</label> <span id="completeDate"></span>
						</td>						
					</tr>
					<tr>
						<td>
							<label>备&nbsp;&nbsp;&nbsp;&nbsp;注</label> <span id="requestComment"></span>
						</td>
						<td id="onpassspan">	
						</td>
					</tr>
				</table>
			</div>
			<p><span id="query"></span><button type="button" onclick="backShow1()">返   回</button></p>
		</form>
	</div>
	<div class="listview1" id="listview1" style='display:none;'>
		<iframe id="requestframe" name="requestframe" style="width:100%;height:90%;overflow:auto;" frameborder=0 src=""></iframe>
	</div>
</body>
</html>